package com.softstao.guoyu.ui.activity.me;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.softstao.guoyu.R;
import com.softstao.guoyu.base.BaseActivity;
import com.softstao.guoyu.global.SharePreferenceManager;
import com.softstao.guoyu.global.UserManager;
import com.softstao.guoyu.model.me.AuditInfo;
import com.softstao.guoyu.model.me.User;
import com.softstao.guoyu.mvp.interactor.me.AuditInteractor;
import com.softstao.guoyu.mvp.presenter.me.AuditPresenter;
import com.softstao.guoyu.mvp.viewer.me.AuditInfoViewer;
import com.softstao.softstaolibrary.library.widget.LZToast;
import com.wangjie.androidinject.annotation.annotations.mvp.AIPresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by vaikus on 2017/6/7.
 */

public class MyAuditActivity extends BaseActivity implements AuditInfoViewer {

    @AIPresenter(presenter = AuditPresenter.class, interactor = AuditInteractor.class)
    AuditPresenter presenter;

    @BindView(R.id.level)
    TextView level;
    @BindView(R.id.mobile)
    TextView mobile;
    @BindView(R.id.wechat)
    TextView wechat;
    @BindView(R.id.idCardNo)
    TextView idCardNo;
    @BindView(R.id.addApply)
    TextView addApply;
    private User user;
    private String level_name;
    private AuditInfo auditInfo;

    @Override
    public int _ContentView() {
        return R.layout.activity_my_audit;
    }

    @Override
    public void initView() {
        initTitle("我的授权");
        user = UserManager.getInstance().getUser();

        switch (User.Type.fromInteger(user.getLevel())) {
            case ANGEL:
                level_name = "天使";
                break;
            case CROWN:
                level_name = "皇冠";
                break;
            case ONE_LEVEL:
                level_name = "一级";
                break;
            case CITY_LEVEL:
                level_name = "市级";
                break;
            case PROVINCE:
                level_name = "省代";
                addApply.setVisibility(View.GONE);
                break;
            case HEADQUARTER:
                level_name = "总部";
                addApply.setVisibility(View.GONE);
                break;
            case UNAGENT:
                level_name = "未授权";
                break;
        }
        level.setText("当前等级：" + level_name);
        mobile.setText(user.getMobile());
        wechat.setText(user.getWechat());
        idCardNo.setText(user.getIdCardNo());
    }

    @OnClick({R.id.addApply, R.id.audit_info, R.id.audit_cert})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.addApply:
                startActivity(new Intent(context, AuditHistoryActivity.class));
                break;
            case R.id.audit_info:
                startActivity(new Intent(context, AuditHistoryActivity.class));
                break;
            case R.id.audit_cert:
                if (auditInfo.getCurrentLevelCertId() == -1) {
                    LZToast.getInstance(context).showToast("该代理暂无授权证书");
                } else {
                    startActivity(new Intent(context, AuditCertActivity.class).putExtra("id",auditInfo.getCurrentLevelCertId()));
                }
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        getAuditInfo();
    }

    @Override
    public void getAuditInfo() {
        presenter.getAuditInfo(SharePreferenceManager.getInstance().getAgentId());
//        presenter.getAuditInfo(5);
    }

    @Override
    public void getResult(AuditInfo auditInfo) {
        if (auditInfo != null) {
            this.auditInfo = auditInfo;
            if (auditInfo.getProcessId()!=0){
                if (auditInfo.getProcessState()==0){
                    addApply.setText("审核中");
                    addApply.setEnabled(false);
                }else if (auditInfo.getProcessState()==1){
                    addApply.setText("已被驳回");
                    addApply.setEnabled(false);
                }
            }else {
                addApply.setText("我要升级");
                addApply.setEnabled(true);
            }
        }
    }
}
